//ztree的搜索方法 
function AutoMatch(txt,ztree) {
		//去除空输入
		var txtObj= txt.replace(/(<br[^>]*>|  |\s*)/g,'');
        if (txtObj.length > 0) {
        	showTreeSearch($("#"+ztree));
            var zTree = $.fn.zTree.getZTreeObj(ztree);//ztree为class="tree"的id
            var nodeList = zTree.getNodesByParamFuzzy("name", txtObj, false);
            var nodeArr = new Array();
            //遍历nodeList
            for (var i = 0; i < nodeList.length; i++) {
                var obj = new Object();
                obj.id = nodeList[i].id;
                obj.pId = nodeList[i].pId;
                obj.name = nodeList[i].name;
                obj.type = nodeList[i].type;//添加节点类型（机构或网点）
                nodeArr.push(obj); 
            }
            
            if(ztree=="organization_structure_ztree"){
            	$.fn.zTree.init($("#"+ztree), structure_setting, nodeArr);
            }else if(ztree=="modal_ztree"){
            	$.fn.zTree.init($("#"+ztree), modal_setting, nodeArr);
            }else if(ztree=="modal_ztree_element"){
            	$.fn.zTree.init($("#"+ztree), modal_setting_element, nodeArr);
            }else if(ztree=="modal_ztree_city"){
            	$.fn.zTree.init($("#"+ztree), city_setting, nodeArr);
            }
			else if(ztree=="parentElement_ztree"){
				$.fn.zTree.init($("#"+ztree), modal_parent_setting, nodeArr);
			}
            else{
            	$.fn.zTree.init($("#"+ztree), setting, nodeArr);
            }
            
        } else {
        	if(ztree=="modal_ztree_city"){
        		showCityTree($("#"+ztree));
        	}else{
        		//showTree($("#"+ztree));
            	showTreeSearch($("#"+ztree));
        	}	
        }
    }
function AutoMatch_model(txt,ztree,mark) {
	//去除空输入
	var txtObj= txt.replace(/(<br[^>]*>|  |\s*)/g,'');
	if (txtObj.length > 0) {
		showElementModelTree($("#"+ztree),mark);
		var zTree = $.fn.zTree.getZTreeObj(ztree);//ztree为class="tree"的id
		var nodeList = zTree.getNodesByParamFuzzy("name", txtObj, false);
		var nodeArr = new Array();
		//遍历nodeList
		for (var i = 0; i < nodeList.length; i++) {
			var obj = new Object();
			obj.id = nodeList[i].id;
			obj.pId = nodeList[i].pId;
			obj.name = nodeList[i].name;
			obj.type = nodeList[i].type;//添加节点类型（机构或网点）
			nodeArr.push(obj);
		}

		if(ztree=="organization_structure_ztree"){
			$.fn.zTree.init($("#"+ztree), structure_setting, nodeArr);
		}else if(ztree=="modal_ztree"){
			$.fn.zTree.init($("#"+ztree), modal_setting, nodeArr);
		}else if(ztree=="modal_ztree_element"){
			$.fn.zTree.init($("#"+ztree), modal_setting_element, nodeArr);
		}else if(ztree=="modal_ztree_city"){
			$.fn.zTree.init($("#"+ztree), city_setting, nodeArr);
		}else{
			$.fn.zTree.init($("#"+ztree), setting, nodeArr);
		}

	} else {
		if(ztree=="modal_ztree_city"){
			showCityTree($("#"+ztree));
		}else{
			//showTree($("#"+ztree));
			showElementModelTree($("#"+ztree),mark);
		}
	}
}
//=================================初始化节点==================================================
function intAttribute(){

	//上网认证有效时间
	$("#authenttime_hour").val("");
	$("#authenttime_min").val("");
	$("#vip_authenttime_hour").val("");
	$("#vip_authenttime_min").val("");
	$("input[name='authenttime_counttype'][value='1']").click();
	$("input[name='vip_authenttime_counttype'][value='1']").click();
	
	
	//上网流量上限
	$("#fluxcount").val("");
	$("#vipfluxcount").val("");
	$("input[name='fluxcounttype'][value='1']").click();
	$("input[name='vipfluxcounttype'][value='1']").click();
	
	//上网时间段
	$("#firstStart").val("");
	$("#firstEnd").val("");
	$("#secondStart").val("");
	$("#secondEnd").val("");

	//短信有效期
	//$("#messageSecond").val("");
	
	//认证方式
	$("input[name='authentType'][value='3']").click();
	$("input[name='phoneType'][value='7']").click();
	$("input[name='accessuserType'][value='5']").click();
	$("input[name='wechatType'][value='3']").click();
	//微信认证配置
	$("#wechatcode,#wechatssid,#wechatshopId,#wechatappId,#wechatsecretKey").val("");
	$("#imageSrc").attr("src","");
	//为url  附上初值
	$("#weChatCodeUrl,#wechatauthUrl").val("http://www.");
	//无流量超时下线
	$("#timeOutOffline").val("");
	
	//最大上网连接数
	$("#connectionslimit").val("");
	
	//二次免认证
	document.getElementById("sfcIsStart").checked=false;
	$("#sfcAvailableday").val("");
	
	//手机配置
/*	document.getElementById("phoneCfgCnc").checked=false;
	document.getElementById("phoneCfgUnicom").checked=false;
	document.getElementById("phoneCfgCmcc").checked=false;
	$("#phoneCfgState").text("");
	$("#phoneCfgMessage").val("");
	
	*/
	$('#accountLoginState').text("未开启");
	$('#phoneLoginState').text("未开启");
	$('#wechatLoginState').text("未开启");

}
//===============================获取认证有效时间数据===========================================================
function getAuthenttime(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getAuthenttime.do",
		data:{
				elementId:$("#elementid").val()
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			var jsonArray = eval("("+jsonStr.rows+")");

			for (var row in jsonArray) {
				var user = jsonArray[row];
				if(user.authentusertype == 1){
					$("#authenttime_hour").val(user.hour);
					$("#authenttime_min").val(user.min);
					if(user.timecounttype == 1){
						$("input[name='authenttime_counttype'][value='1']").click();
					}else{
						$("input[name='authenttime_counttype'][value='2']").click();
					}
				}else{
					$("#vip_authenttime_hour").val(user.hour);
					$("#vip_authenttime_min").val(user.min);
					if(user.timecounttype == 1){
						$("input[name='vip_authenttime_counttype'][value='1']").click();
					}else{
						$("input[name='vip_authenttime_counttype'][value='2']").click();
					}
				}
			}
		},
		error: function(data){
			//alert("认证有效期get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

function setAuthenttime(){
	var ids = new Array();
	ids[0]="#authenttime_counttype";
	ids[1]="#authenttime_hour";
	ids[2]="#authenttime_min";
	ids[3]="#vip_authenttime_counttype";
	ids[4]="#vip_authenttime_hour";
	ids[5]="#vip_authenttime_min";

	if(isSubmitForm(ids)){
	$.ajax({
		type: "POST",
		url: $(path).val() + "/config/setAuthenttime.do",
		data: {
			elementid: $("#elementid").val(),
			timecounttype: $("input[name='authenttime_counttype']:checked").val(),
			hour: $("#authenttime_hour").val(),
			min: $("#authenttime_min").val(),
			authentusertype: 1,
			//vip用户
			vip_timecounttype: $("input[name='vip_authenttime_counttype']:checked").val(),
			vip_hour: $("#vip_authenttime_hour").val(),
			vip_min: $("#vip_authenttime_min").val(),
		},
		async: false,
		cache: false,
		success: function (data) {
			swal("操作成功！", "", "success");
			getAuthenttime();
			initEles(ids);
		},
		error: function (data) {
			//alert("认证有效期set");
			swal("系统异常,请联系系统管理员!", "", "error");
		}

	});
	}// end if
}

//===============================获取流量上限数据============================
function getFluxout(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getFluxout.do",
		data:{
				elementId:$("#elementid").val()
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			var jsonArray = eval("("+jsonStr.rows+")");
			
			for (var row in jsonArray) {
				var user = jsonArray[row];
				if(user.authentusertype == 1){
					$("#fluxcount").val(user.fluxcount);
					if(user.fluxcounttype == 1){
						$("input[name='fluxcounttype'][value='1']").click();
					}else{
						$("input[name='fluxcounttype'][value='2']").click();
					}
				}else{
					$("#vipfluxcount").val(user.fluxcount);
					if(user.fluxcounttype == 1){
						$("input[name='vipfluxcounttype'][value='1']").click();
					}else{
						$("input[name='vipfluxcounttype'][value='2']").click();
					}
				}
			}
		},
		error: function(data){
			//alert("流量上限get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

function setFluxout(){
	var ids = new Array();
	ids[0]="#fluxcounttype";
	ids[1]="#fluxcount";
	ids[2]="#vipfluxcounttype";
	ids[3]="#vipfluxcount";
	//alert("1"+isSubmitForm(ids));
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setFluxout.do",
			data: {
				elementid: $("#elementid").val(),
				fluxcounttype: $("input[name='fluxcounttype']:checked").val(),
				fluxcount: $("#fluxcount").val(),
				authentusertype: 1,
				//vip用户
				vipfluxcounttype: $("input[name='vipfluxcounttype']:checked").val(),
				vipfluxcount: $("#vipfluxcount").val(),
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getFluxout();initEles(ids);
			},
			error: function (data) {
				//alert("流量上限set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

//===============================上网时间段===========================
function getNetTime(){
	
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getNetTime.do",
		data:{
				elementId:$("#elementid").val()
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			var jsonArray = eval("("+jsonStr.rows+")");
			
			for (var row in jsonArray) {
				var user = jsonArray[row];
				if(user.authentusertype == 1){
					$("#firstStart").val(user.begintime);
					$("#firstEnd").val(user.endtime);
					console.log(user.begintime);
				}else{
					$("#secondStart").val(user.begintime);
					$("#secondEnd").val(user.endtime);
				}
			}
		},
		error: function(data){
			//alert("上网时间段get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

function setNetTime(){
	var ids = new Array();
	ids[0]="#firstStart";
	ids[1]="#firstEnd";
	ids[2]="#secondStart";
	ids[3]="#secondEnd";
	//alert("上网时间段"+isSubmitForm(ids));
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setNetTime.do",
			data: {
				elementid: $("#elementid").val(),
				begintime: $("#firstStart").val(),
				endtime: $("#firstEnd").val(),
				authentusertype: 1,
				//vip用户
				vipbegintime: $("#secondStart").val(),
				vipendtime: $("#secondEnd").val(),
			},
			async: false,
			cache: false,
			success: function (data) {
				//alert("上网时间段set");
				swal("操作成功！", "", "success");
				getNetTime();initEles(ids);
			},
			error: function (data) {
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

//===========================短信有效期

function getMessage(){

	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getMessage.do",
		data:{
				elementId:$("#elementid").val()
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			//$("#messageSecond").val(jsonStr.second);
		},
		error: function(data){
			//alert("短信有效期get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

function setMessage(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/setMessage.do",
		data:{
			elementid:$("#elementid").val(),
			//second:$("#messageSecond").val()
			},
		async: false,
		cache: false,
		success: function(data){
			swal("操作成功！", "", "success");
			getMessage();initEles(ids);
		},
		error: function(data){
			//alert("短信有效期set");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

//=================================================认证设置

function getAthenttype(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getAuthenttype.do",
		data:{
				elementId:$("#elementid").val()
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			var jsonArray = eval("("+jsonStr.rows+")");

			for (var row in jsonArray) {
				var user = jsonArray[row];
				
				if(user.authentType == 1 && user.isStart == "Y"){
					//免认证
					$("input[name='authentType'][value='1']").click();
				}

				if(user.authentType == 2 && user.isStart == "Y"){
					//一键认证
					$("input[name='authentType'][value='2']").click();
				}
				
				if(user.authentType == 3 && user.isStart == "Y"){
					//手机登入
					$("input[name='authentType'][value='3']").click();
					$("input[name='phoneType'][value='6']").click();
					$("#phoneRenZheng").show();
					$('#phoneLoginState').text("开启");

				}
				
				if(user.authentType == 4 && user.isStart == "Y"){
					//固定账号
					$("input[name='authentType'][value='3']").click();
					$("input[name='accessuserType'][value='4']").click();
					$('#accountLoginState').text("开启");
					$("#btngroup").css("display","");
				}
				if(user.authentType == 5 && user.isStart == "Y"){
					//微信账号
					$("input[name='authentType'][value='3']").click();
					$("input[name='wechatType'][value='1']").click();
					$('#wechatLoginState').text("开启");
				}
			}
		},
		error: function(data){
			//alert("认证方式get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

function setAthenttype(){
	var ids = new Array();
	ids[0]="#authentType";
	ids[1]="#accessuserType";
	ids[2]="#phoneType";
	ids[3]="#wechatType";

	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setAuthenttype.do",
			data: {
				elementid: $("#elementid").val(),
				authentType: $("input[name='authentType']:checked").val(),
				accessuserType: $("input[name='accessuserType']:checked").val(),
				phoneType: $("input[name='phoneType']:checked").val(),
				wechatType: $("input[name='wechatType']:checked").val(),
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				initEles(ids);
			},
			error: function (data) {
				//alert("认证方式set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

//======================================微信配置============================

function getWeChatCFG(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getWeChatCFG.do",
		data:{
				elementId:$("#elementid").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			$("#wechatauthUrl").css("color", "#676a6c");
			$("#weChatCodeUrl").css("color", "#676a6c");
			$("#wechatcode").css("color", "#676a6c");
			var jsonStr=eval("("+data+")");
			$("#wechatssid").val(jsonStr.ssid);
			$("#wechatappId").val(jsonStr.appid);
			$("#wechatshopId").val(jsonStr.shopid);
			$("#wechatsecretKey").val(jsonStr.secretkey);
			$("#wechatauthUrl").val(jsonStr.authUrl);
			$("#weChatCodeUrl").val(jsonStr.weChatCodeUrl);
			$("#wechatcode").val(jsonStr.wechatcode);
			$("#imageSrc").attr('src',"/pic/"+jsonStr.elementid+"/"+jsonStr.qrcodepath);
			$("#imageSrc").data("default",jsonStr.qrcodepath);
			$(".file-caption-name").attr("title","").html("");
			$(".fileinput-remove-button").click();
			//alert("/pic/"+jsonStr.elementid+"/"+jsonStr.qrcodepath);

			if(jsonStr.wechatlogintype==1){
				$("input[name='wechatType'][value='1']").click();
				$("#weixinRenZheng").show();
			}
			if(jsonStr.wechatlogintype==2){
				$("input[name='wechatType'][value='2']").click();
				$("#weixinLianWifi").show();
			}
			if(jsonStr.wechatlogintype==3){
				$("input[name='wechatType'][value='3']").click();
			}
			
		},
		error: function(data){
			//alert("微信get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
function setWeChatCFG(){

	var ids = new Array();
	ids[0]="#wechatssid";
	ids[1]="#wechatappId";
	ids[2]="#wechatshopId";
	ids[3]="#wechatsecretKey";
	ids[4]="#weChatCodeUrl";
	ids[5]="#qrcodepath";
	ids[6]="#wechatcode";
	ids[7]="#wechatType";
	ids[8]="#wechatauthUrl";
	if(isSubmitForm(ids)) {
		var imagePath=$("#qrcodepath").val();
		//判断是否有新上传图片，没有的话吧原有的名字上传
if(imagePath==""&&$("#imageSrc").data("default")!=""){
	imagePath=$("#imageSrc").data("default");
}
//公众号的中文乱码
		var wechatcode=encodeURI(encodeURI($("#wechatcode").val()));
		$.ajaxFileUpload({
			url: $(path).val() + '/config/setWeChatCFG.do?&elementid=' + $("#elementid").val() + '&ssid=' + $("#wechatssid").val()
			+ '&appid=' + $("#wechatappId").val() + '&shopid=' + $("#wechatshopId").val() + '&secretkey=' + $("#wechatsecretKey").val() +'&authUrl='+$("#wechatauthUrl").val()+ '&weChatCodeUrl=' + $("#weChatCodeUrl").val()
			+ '&qrcodepath=' + imagePath + '&wechatcode=' + wechatcode + '&wechatlogintype=' + $("input[name='wechatType']:checked").val(),
			secureuri: false,                       //是否启用安全提交,默认为false
			fileElementId: 'qrcodepath',           		//文件选择框的id属性
			dataType: 'json',                       //服务器返回的格式,可以是json或xml等
			success: function (data) {        //服务器响应成功时的处理函数
				swal("操作成功！", "", "success");
				getWeChatCFG();initEles(ids);

			},
			error: function (data, status, e) { //服务器响应失败时的处理函数
				swal('微信数据更新失败，请重试！！');
			}
		});
	}
}

//==================================================无流量超时下线
function getTimeOutOffline(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getTimeOutOffline.do",
		data:{
				elementId:$("#elementid").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			/*var jsonStr=eval("("+data+")");
			$("#timeOutOffline").val(jsonStr.timelimit);*/
			var jsonStr=eval("("+data+")");
			var jsonArray = eval("("+jsonStr.rows+")");			
			for (var row in jsonArray) {
				var user = jsonArray[row];
				$("#timeOutOffline").val(user.timelimit/60);
				}
		},
		error: function(data){
			//alert("无流量下线get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
function setTimeOutOffline(){
	var ids = new Array();
	ids[0]="#timeOutOffline";
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setTimeOutOffline.do",
			data: {
				elementid: $("#elementid").val(),
				timelimit: $("#timeOutOffline").val() * 60
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getTimeOutOffline();initEles(ids);
			},
			error: function (data) {
				//alert("无流量超时set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}


//==========================================================最大上网连接数

function getConnectionslimit(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getConnectionslimit.do",
		data:{
				elementId:$("#elementid").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			$("#connectionslimit").val(jsonStr.connections);
		},
		error: function(data){
			//alert("最大上网连接数get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
function setConnectionslimit(){
	var ids = new Array();
	ids[0]="#connectionslimit";
	//alert("最大上网连接数"+isSubmitForm(ids));
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setConnectionslimit.do",
			data: {
				elementid: $("#elementid").val(),
				connections: $("#connectionslimit").val(),
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getConnectionslimit();initEles(ids);
			},
			error: function (data) {
				//alert("最大上网连接数set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

//==================================================二次免认证
function getSecFreeCret(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getSecFreeCret.do",
		data:{
				elementId:$("#elementid").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			
			if(jsonStr.isStart == "Y"){
				
				document.getElementById("sfcIsStart").checked=true;
			}else{
				document.getElementById("sfcIsStart").checked=false;
			}
			
			$("#sfcAvailableday").val(jsonStr.availableDay);
		},
		error: function(data){
			//alert("二次免认证get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
function setSecFreeCret(){
	var ids = new Array();
	ids[0]="#sfcAvailableday";
	ids[1]="#sfcIsStart";
	//alert("二次免认证"+isSubmitForm(ids));
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setSecFreeCret.do",
			data: {
				elementid: $("#elementid").val(),
				availableDay: $("#sfcAvailableday").val(),
				isStart: $("#sfcIsStart").val()
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getSecFreeCret();initEles(ids);
			},
			error: function (data) {
				//alert("二次免认证set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

//==================================================手机认证
function getPhoneCfg(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/getPhoneCfg.do",
		data:{
				elementId:$("#elementid").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			var jsonStr=eval("("+data+")");
			document.getElementById("phoneCfgCnc").checked=jsonStr.iscnc == "Y"? true:false;
			document.getElementById("phoneCfgUnicom").checked=jsonStr.isunicom == "Y"? true:false;
			document.getElementById("phoneCfgCmcc").checked=jsonStr.iscmcc == "Y"? true:false;

			$("#phoneCfgState").text(jsonStr.auditstate == 1? "正常" : "非正常");
		//	$("#phoneCfgMessage").val(jsonStr.message);
		},
		error: function(data){
			//alert("手机认证get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
function setPhoneCfg(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/setPhoneCfg.do",
		data:{
			elementid:$("#elementid").val(),
			iscnc:$("#phoneCfgCnc").is(":checked")==true? "Y":"N",
			isunicom:$("#phoneCfgUnicom").is(":checked")==true? "Y":"N",
			iscmcc:$("#phoneCfgCmcc").is(":checked")==true? "Y":"N",
			message:$("#phoneCfgMessage").val(),
			},
		async: false,
		cache: false,
		success: function(data){
			swal("操作成功！", "", "success");
		},
		error: function(data){
			//alert("手机认证set");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
//==================================================规则配置
function setPolicy(){
	var ids = new Array();
	ids[0]="#selectPolicy";
	if(isSubmitForm(ids)) {
		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/ruleManage/setChoosePolicy.do",
			data: {
				elementId: $("#elementid").val(),
				policyId: $("#selectPolicy").val()
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getPolicy();initEles(ids);
			},
			error: function (data) {
				//alert("规则set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}

function getPolicy(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/ruleManage/getChoosePolicy.do",
		data:{
			elementMode:$("#elementMode").val(),
			elementId:$("#elementid").val()
		},
		async: false,
		cache: false,
		success: function(data){
			$("#selectPolicy").html(data);
		},
		error: function(data){
			//alert("规则get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}
//===================================================广告配置

function setStrategy_Ad(){
	var sid = $("#selectStrategy_Ad").val();
	var str = (sid+"").replace(/,/g, "a");//将字符串中的,替换成a用于数据传输
	var ids = new Array();
	ids[0]="#selectStrategy_Ad";

	if($(ids[0]).data("default")!=($(ids[0]).val()+"")&&($(ids[0]).data("default")!=null||$(ids[0]).val()!=null)) {

		$.ajax({
			type: "POST",
			url: $(path).val() + "/config/setElmStrategy_Ad.do",
			data: {
				strategyId: str,
				elementId: $("#elementid").val()
			},
			async: false,
			cache: false,
			success: function (data) {
				swal("操作成功！", "", "success");
				getStrategy_Ad();initEles(ids);
			},
			error: function (data) {
				//alert("广告set");
				swal("系统异常,请联系系统管理员!", "", "error");
			}
		});
	}
}
function getStrategy_Ad(){
	$.ajax({
		type:"POST",
		url:$(path).val()+"/config/selectStrategy_AdbyUserId.do",
		data:{
			elementId:$("#elementid").val()
		},
		async: false,
		cache: false,
		success: function(data){
			$("#selectStrategy_Ad").html(data);
			$('#selectStrategy_Ad').selectpicker('refresh');
		},
		error: function(data){
			//alert("广告get");
			swal("系统异常,请联系系统管理员!", "", "error");
		}
	});
}

//==================================================上网设置(预设)
function getNetAttribute(){
	//认证有效时间
	getAuthenttime();
	//上网流量上限
	getFluxout();
	//上网时间段
	getNetTime();
	//认证方式
	getAthenttype();
    //固定账户表格重置
	$.jgrid.gridUnload("table_list");
	UserTable();
	//微信配置
	getWeChatCFG();
	//无流量超时下线
	getTimeOutOffline();
	//最大上网连接数
	getConnectionslimit();
	//二次免认证
	getSecFreeCret();
	//规则管理选择
	getPolicy();
	//广告模版管理选择
	getStrategy_Ad();
	//手机认证
	//getPhoneCfg();
	//短信有效期
	//getMessage();
	initDefault();
}

function setNetAttribute(){//(保存配置)
	/*	//认证方式
	 setAthenttype();
	 //手机认证
	 setPhoneCfg();
	 //微信配置
	 setWeChatCFG();*/
	setWeChatCFG();
	setAthenttype();

	if($("input[name='authentType']:checked").val()!=1){
		//保存上网认证有效时间配置
		setAuthenttime();
		//流量上限
		setFluxout();
		//上网时间段
		setNetTime();
		//无流量超时下线
		setTimeOutOffline();
		//最大上网连接数
		setConnectionslimit();
		//二次免认证
		setSecFreeCret();
		//规则管理选择
		setPolicy();
		//广告模版管理选择
		setStrategy_Ad();
		//短信有效时间
		//setMessage();
	}
//initDefault();

}



//===============================刷新节点信息数据==========================================================
function freshAttribute(){

	//先初始化属性
	intAttribute();
	
	if($('#elementid').val()==""){
		return;
	}
	 $.ajax({
	   		type:"POST",
	   		url:$(path).val()+"/config/viewElement.do",
	   		data:{
	   				elementId:$('#elementid').val()
	   			},
	   		async: false,
	   		cache: false,
	   		success: function(data){
	   			var jsonStr=eval("("+data+")");
	   			var element=jsonStr.element;
                var title="";
				$("#elementMode").val(element.elementmode);
				if(element.elementtype=="2")
                    title="具体配置(当前网点:"+element.elementname+")";
				else title="具体配置(当前机构:"+element.elementname+")";
                if(element.isextends=="1"){ title+="<---(上级配置)";
                //去取最靠近的上级自定义配置

                    $.ajax({
                        type:"POST",
                        url:$(path).val()+"/config/ParentElement.do",
                        data:{
                            elementId:$('#elementid').val()
                        },

                        success: function(data) {
                            var result=$.parseJSON(data);
                            $('#elementid').val(result.elementid);
                            getNetAttribute();
                        }
                        })

                }
                else {title+="<---(自定义配置)";getNetAttribute();}
                $("#detailTitle").html(title);

				// 当配置方式为 上级配置(保存是否可用)
				if(element.isextends==1){

					$("#Btn_saveAttributes,#Btn_saveAccUser,#Btn_savePhone,#Btn_saveWeixin,#delBtn,#editBtn,#addBtn").css("display","none");
				}
				else{
					$("#Btn_saveAttributes,#Btn_saveAccUser,#Btn_savePhone,#Btn_saveWeixin,#delBtn,#editBtn,#addBtn").css("display","");
				}
				if(element.elementmode==1){
					//当前为base模式
					//$("#gateway").hide();
					//$("#base").show();
					$("#elementMode").val("1");
				}else{
					$("#elementMode").val("2");
				}
					//网关模式

					//认证设置
						//固定账号

						//手机登入
						//微信登入
					
					//上网设置



				$("#base").hide();
				$("#gateway").show();
					
				
	   		},
	   		error: function(data){
	   			swal("系统异常,请联系系统管理员!", "", "error");
	   		}
	   	});
}
//===============================显示搜索后的组织结构树==========================================================	
function organization_structure_input(){
	var ztree="organization_structure_ztree";
	AutoMatch(this.value,ztree);
}


//================================显示搜索区域，input输入之后的组织结构树=============================================
function input(){
	$("#netWorkId").val('');
	var ztree="ztree";
	AutoMatch(this.value,ztree);
}

function modal_Input(){
	
	var ztree="modal_ztree";
	AutoMatch(this.value,ztree);
}
function modal_Input1(){

	var ztree="parentElement_ztree";
	AutoMatch(this.value,ztree);
}
function modal_Input2(){
	
	var ztree="modal_ztree";
	AutoMatch_model(this.value,ztree,2);
}
function modal_Input3(){

	var ztree="modal_ztree";
	AutoMatch_model(this.value,ztree,3);
}
//===============================显示完整的组织结构树==========================================================		
function showTree(treeId){
	$.ajax({
				type:"POST",
				async: false,
				url: $(path).val()+"/config/showElements.do",
				data:{'date' :'new Date().getTime()'},
				dataType:"json",
				success:function(data){
					if(treeId.attr("id")=="organization_structure_ztree"){
			        	t = $.fn.zTree.init(treeId, structure_setting, data.rows);
			        }else{
			        	t = $.fn.zTree.init(treeId, setting, data.rows);
			        }

					//初始化树状态，默认显示树的第一个节点的属性
					var treeObj = $.fn.zTree.getZTreeObj("organization_structure_ztree");
					var node = treeObj.getNodes()[0];
					if($("#elementid").val()=="") {
						if (node) {
							$('#elementid').val(node.id);
						} else {
                            $.jgrid.gridUnload("table_list");
                            UserTable();
						}
					}
					//刷新属性
					freshAttribute();
				}
			});
}
function parentElementTree(treeId){

	$.ajax({
		type:"POST",
		async: false,
		url: $(path).val()+"/config/showElements.do",
		data:{'mark' :'1'},
		dataType:"json",
		success:function(data){
			t = $.fn.zTree.init(treeId, modal_parent_setting, data.rows);
			//初始化树状态，默认显示树的第一个节点的属性
			//var treeObj = $.fn.zTree.getZTreeObj("parentElement_ztree");
			//var node = treeObj.getNodes()[0];
		}
	});

}

//====================================搜索中的网点组织结构树显示======================================================

function showTreeSearch(treeId){

	$.ajax({
				type:"POST",
				async: false,
				url: $(path).val()+"/config/showElements.do",
				data:{'date' :'new Date().getTime()'},
				dataType:"json",
				//cache:true,
				success:function(data){
					if(treeId.attr("id")=="organization_structure_ztree"){
						t = $.fn.zTree.init(treeId, structure_setting, data.rows);
					}else if(treeId.attr("id")=="modal_ztree"){
			        	t = $.fn.zTree.init(treeId, modal_setting, data.rows);
			        }
					else if(treeId.attr("id")=="modal_ztree2"){
						t = $.fn.zTree.init(treeId, modal_setting2, data.rows);
					}
			        else if(treeId.attr("id")=="modal_ztree_element"){
			        	t = $.fn.zTree.init(treeId, modal_setting_element, data.rows);
			        }else{
			        	t = $.fn.zTree.init(treeId, setting, data.rows);
    				}

				}
			});
}
//==============================bas和网关归属的tree=========================
function showElementModelTree(treeId,mark){
// mark 2 : bas   3 :网关
	$.ajax({
		type:"POST",
		async: false,
		url: $(path).val()+"/config/showElements.do",
		data:{'mark' :mark},
			dataType:"json",
			//cache:true,
			success:function(data){
				if(treeId.attr("id")=="organization_structure_ztree"){
					t = $.fn.zTree.init(treeId, structure_setting, data.rows);
				}else if(treeId.attr("id")=="modal_ztree"){
					t = $.fn.zTree.init(treeId, modal_setting, data.rows);
				}else if(treeId.attr("id")=="modal_ztree_aiwifi"){
		        	t = $.fn.zTree.init(treeId, modal_setting_aiwifi, data.rows);
		        }else if(treeId.attr("id")=="modal_ztree_element"){
					t = $.fn.zTree.init(treeId, modal_setting_element, data.rows);
				}else{
					t = $.fn.zTree.init(treeId, setting, data.rows);
				}

			}
		});
}
//===================================标签默认值设置===============
function initDefault(){
//  为元素建立 默认值  采用data（name,value）形式
	$("input,select").each(function(){
		if($(this).attr("type")!="radio"&&$(this).attr("type")!="button") {
			$(this).data("default",$(this).val());
		}
		else if($(this).attr("type")=="radio"){
			$(this).data("default",$("input[name='"+$(this).attr("name")+"']:checked").val());
		}

	})

}
function initEles(ids){
	for(var i=0;i<ids.length;i++){
		if($(ids[i]).attr("type")=="radio") {
			$(ids[i]).data("default", $("input[name='"+$(ids[i]).attr("name")+"']:checked").val());
		}
		else{
			$(ids[i]).data("default",$(ids[i]).val());
		}
	}
}
//==================================判断元素是否被修改  $(参数)
function isReset(ele){
	if($(ele).attr("type")=="radio"){

		if ($(ele).data("default") == $("input[name='"+$(ele).attr("name")+"']:checked").val()) {
			return false;
		}
	}
	else {
		if ($(ele).data("default") == $(ele).val()) {
			return false;
		}
	}
	return true;
}
// 判断表单是否需要提交保存（有无元素修改）
function isSubmitForm(ids){
	for(var i=0;i< ids.length;i++)
	{
		if(isReset(ids[i])){ return true;}
	}
	return false;
}
////////////////////
//  滚动条到底部
function scrollDown() {
	var h = $(document).height() - $(window).height();
	$(document).scrollTop(h);
}